package com.baihan.angus.app.game.busshow.adps;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.baihan.angus.app.game.basic.BaseApplication;
import com.baihan.angus.app.game.basic.base.BaseAdp;
import com.baihan.angus.app.game.busshow.R;
import com.baihan.angus.app.game.common.bean.entity.ClueEntity;
import com.baihan.angus.app.game.common.util.ImageLoader;
import com.qmuiteam.qmui.widget.QMUIRadiusImageView;

public class DmClueAdp extends BaseAdp<ClueEntity, DmClueAdp.ViewHolder> {

    private OnItemClickListener mOnItemClickListener;

    @Override
    protected RecyclerView.ViewHolder createYourViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_dm_clue, parent, false);
        return new ViewHolder(view);
    }

    @Override
    protected void bindYourViewHolder(@NonNull ViewHolder holder, int position) {
        ViewHolder vh = holder;

        ClueEntity item = getItem(position);

        vh.tvTitle.setText(item.getTitle());

        ImageLoader.loadImage(BaseApplication.getApplication().getApplicationContext(),
                vh.ivClue, item.getUrl().get(0).getUrl(), R.mipmap.ic_test_bg, 0);

        if (item.getIs_send() == 0) {//0-未发送 1-已发送
            vh.tvSend.setEnabled(true);
        } else {
            vh.tvSend.setEnabled(false);
        }

        if (item.getIs_open() == 0) {//0-未公开 1-已公开
            vh.tvOpen.setEnabled(true);
        } else {
            vh.tvOpen.setEnabled(false);
        }

        vh.tvSend.setOnClickListener(v -> {
            mOnItemClickListener.onSend(position);
        });

        vh.tvOpen.setOnClickListener(v -> {
            mOnItemClickListener.onOpen(position);
        });

        vh.llClueItem.setOnClickListener(v -> {
            mOnItemClickListener.onItemClick(position);
        });
    }

    @Override
    protected int getEmptyView() {
        return 0;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        TextView tvTitle, tvSend, tvOpen;
        QMUIRadiusImageView ivClue;
        LinearLayout llClueItem;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvTitle = itemView.findViewById(R.id.tvTitle);
            tvSend = itemView.findViewById(R.id.tvSend);
            tvOpen = itemView.findViewById(R.id.tvOpen);
            ivClue = itemView.findViewById(R.id.ivClue);
            llClueItem = itemView.findViewById(R.id.llClueItem);
        }
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClick(int position);
        void onSend(int position);
        void onOpen(int position);
    }
}
